
clear all 
set more off 

// Replication for "Crossing the District Line: Border Mismatch and Targeted Redistribution"
// March, 2025 
// Allison Stashko

// Dataset Construction

// Set path for Replication Folder 

global ReplicationPath "~/Dropbox/Econ/Unequal Votes/Replication_JOP/"  //note: use full path for mv command

global RawDataPath "$ReplicationPath/1_Data/raw_data"
global CodePath "$ReplicationPath/1_Data/code"  
global InputPath "$ReplicationPath/1_Data/input"
global OutputPath "$ReplicationPath/1_Data/output/"


// install packages if necessary
ssc install statastates, replace


// run all data construction files 

cd   "$CodePath"

// Generate intermediate datasets from publically avialable raw data.

do "$CodePath/0_1_censusblock_assign.do"
do "$CodePath/0_2_census_pop.do"
do "$CodePath/0_3_elections_csld.do"
do "$CodePath/0_4_elections_csld_2014.do"
do "$CodePath/0_5_0_statelegislators.do"
do "$CodePath/0_5_1_statelegislators_upper.do" 
do "$CodePath/0_6_GovFin_allincounty.do"
do "$CodePath/0_7_nhgis.do"
do "$CodePath/0_8_Payson_Lobbying.do" 
do "$CodePath/0_9_NCES_school_districts.do" 

// Combine intermediate datasets to construct final dataset

do "$CodePath/1_collapse_county_sldl.do"
do "$CodePath/2_0_merge_election_data.do" 
do "$CodePath/2_1_merge_election_data_upper.do" 
do "$CodePath/3_0_collapse_county.do" 
do "$CodePath/3_1_collapse_county_upper.do" 
do "$CodePath/4_merge_county_data.do"
do "$CodePath/5_gen_vars.do"


cd "$OutputPath/"
export delim countydistrict.csv, replace

